package com.seuic.hnapps.project;


import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.widget.CardView;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.orhanobut.logger.Logger;
import com.seuic.hnapps.BaseActivity;
import com.seuic.hnapps.R;
import com.seuic.hnapps.SquareLayout;
import com.seuic.hnapps.adapter.Select_subaccount_adapter;
import com.seuic.hnapps.bean.CardBinInfo_bean;
import com.seuic.hnapps.bean.Select_subaccount_Bean;
import com.seuic.hnapps.bean.StatisticalData_bean;
import com.seuic.hnapps.bean.Summary_Bean;
import com.seuic.hnapps.constants.EmvConstants;
import com.seuic.hnapps.posdsdk.pos_func.PosCallbacks;
import com.seuic.hnapps.posdsdk.pos_func.PosFuncs;
import com.seuic.hnapps.util.CommAdapter;
import com.seuic.hnapps.util.Constants;
import com.seuic.hnapps.util.DateUtil;
import com.seuic.hnapps.util.HNYQInterface;
import com.seuic.hnapps.util.LTFInterface;
import com.seuic.hnapps.util.LTPInstall;
import com.seuic.hnapps.util.LTSInstall;
import com.seuic.hnapps.util.PinPad;
import com.seuic.hnapps.util.PzGetUtils;
import com.seuic.hnapps.util.SBAhnInterface;
import com.seuic.hnapps.util.ServiceCommon;
import com.seuic.hnapps.util.SpUtils;
import com.seuic.hnapps.util.Up_RundataUtils;
import com.seuic.hnapps.util.Utils;
import com.seuic.hnapps.util.VTAInterface;
import com.seuic.hnapps.util.YDPInstall;
import com.seuic.hnapps.util.YDSInstall;
import com.solab.enc.DES3;
import com.solab.enc.HexT;
import com.solab.enc.SMS4;
import com.solab.iso8583.IsoMessage;
import com.solab.iso8583.MessageFactory;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * isjingkai
 * 2019年7月20日10:53:33
 * 代理缴费
 */

public class ChargeAgencyActivity extends BaseActivity {
    Runnable runnable;
    Handler handler;


    @BindView(R.id.base_back_btn)
    LinearLayout baseBackBtn;
    @BindView(R.id.base_title_text)
    TextView baseTitleText;
    @BindView(R.id.charge_agency_payment)
    SquareLayout chargeAgencyPayment;
    @BindView(R.id.charge_agency_Wisdomtosave)
    SquareLayout chargeAgencyWisdomtosave;
    @BindView(R.id.charge_agency_Unicompayment)
    SquareLayout chargeAgencyUnicompayment;
    @BindView(R.id.charge_agency_hnwin)
    SquareLayout chargeAgencyHnwin;
    @BindView(R.id.charge_agency_layout)
    LinearLayout chargeAgencyLayout;
    @BindView(R.id.input_phone_edtext)
    EditText inputPhoneEdtext;
    @BindView(R.id.input_phone_nobtn)
    Button inputPhoneNobtn;
    @BindView(R.id.input_phone_okbtn)
    Button inputPhoneOkbtn;
    @BindView(R.id.input_phone_num_layout)
    LinearLayout inputPhoneNumLayout;
    @BindView(R.id.dealing_layout)
    LinearLayout dealingLayout;
    @BindView(R.id.input_recharge_amount_edtext)
    EditText inputRechargeAmountEdtext;
    @BindView(R.id.input_recharge_amount_name)
    TextView inputRechargeAmountName;
    @BindView(R.id.input_recharge_amount_phoneNum)
    TextView inputRechargeAmountPhoneNum;
    @BindView(R.id.input_recharge_amount_type)
    TextView inputRechargeAmountType;
    @BindView(R.id.input_recharge_amount_balance)
    TextView inputRechargeAmountBalance;
    @BindView(R.id.input_recharge_amount_noBtn)
    Button inputRechargeAmountNoBtn;
    @BindView(R.id.input_recharge_amount_yesBtn)
    Button inputRechargeAmountYesBtn;
    @BindView(R.id.input_recharge_amount_layout)
    LinearLayout inputRechargeAmountLayout;
    @BindView(R.id.ficationing_layout)
    LinearLayout ficationingLayout;
    //    @BindView(R.id.please_input_iccard_okbtn)
//    Button pleaseInputIccardOkbtn;
    @BindView(R.id.please_input_iccard_layout)
    LinearLayout pleaseInputIccardLayout;
    @BindView(R.id.sure_payment_money)
    TextView surePaymentMoney;
    @BindView(R.id.sure_payment_phonenum)
    TextView surePaymentPhonenum;
    @BindView(R.id.sure_payment_noBtn)
    Button surePaymentNoBtn;
    @BindView(R.id.sure_payment_yesBtn)
    Button surePaymentYesBtn;
    @BindView(R.id.sure_payment_layout)
    LinearLayout surePaymentLayout;
    @BindView(R.id.topup_success_num)
    TextView topupSuccessNum;
    @BindView(R.id.topup_success_time)
    TextView topupSuccessTime;
    @BindView(R.id.topup_success_type)
    TextView topupSuccessType;
    @BindView(R.id.topup_success_typesey)
    TextView topupSuccessTypesey;
    @BindView(R.id.topup_success_btn)
    Button topupSuccessBtn;
    @BindView(R.id.topup_success_layout)
    LinearLayout topupSuccessLayout;
    @BindView(R.id.select_pay_type_xj_btn)
    Button selectPayTypeXjBtn;
    @BindView(R.id.select_pay_type_bank_btn)
    Button selectPayTypeBankBtn;
    @BindView(R.id.select_pay_type_layout)
    LinearLayout selectPayTypeLayout;
    @BindView(R.id.sure_printingpeper_okbtn)
    Button surePrintingpeperOkbtn;
    @BindView(R.id.sure_printingpeper_layout)
    LinearLayout surePrintingpeperLayout;
    @BindView(R.id.printing_layout)
    LinearLayout printingLayout;
    @BindView(R.id.live_to_atfixedperiod_btn)
    Button liveToAtfixedperiodBtn;
    @BindView(R.id.atfixedperiod_to_live_btn)
    Button atfixedperiodToLiveBtn;
    @BindView(R.id.live_transfers_layout)
    LinearLayout liveTransfersLayout;
    @BindView(R.id.input_customanager_edtext)
    EditText inputCustomanagerEdtext;
    @BindView(R.id.input_customanager_gzbtn)
    Button inputCustomanagerGzbtn;
    @BindView(R.id.input_customanager_okbtn)
    Button inputCustomanagerOkbtn;
    @BindView(R.id.input_customanager_layout)
    LinearLayout inputCustomanagerLayout;
    @BindView(R.id.hny_info_num)
    TextView hnyInfoNum;
    @BindView(R.id.hny_info_money)
    TextView hnyInfoMoney;
    @BindView(R.id.hny_info_gzbtn)
    Button hnyInfoGzbtn;
    @BindView(R.id.hny_info_okbtn)
    Button hnyInfoOkbtn;
    @BindView(R.id.hny_info_layout)
    LinearLayout hnyInfoLayout;
    @BindView(R.id.input_money_title)
    TextView inputMoneyTitle;
    @BindView(R.id.input_money_edtext)
    EditText inputMoneyEdtext;
    @BindView(R.id.input_money_gzbtn)
    Button inputMoneyGzbtn;
    @BindView(R.id.input_money_okbtn)
    Button inputMoneyOkbtn;
    @BindView(R.id.input_money_layout)
    LinearLayout inputMoneyLayout;
    @BindView(R.id.select_subaccount_recyclerview)
    RecyclerView selectSubaccountRecyclerview;
    @BindView(R.id.select_subaccount_layout)
    CardView selectSubaccountLayout;
    @BindView(R.id.charge_agency_home_layout)
    CardView chargeAgencyHomeLayout;
    @BindView(R.id.live_transfers_success_usernum)
    TextView liveTransfersSuccessUsernum;
    @BindView(R.id.live_transfers_success_money)
    TextView liveTransfersSuccessMoney;
    @BindView(R.id.live_transfers_success_dealtype)
    TextView liveTransfersSuccessDealtype;
    @BindView(R.id.live_transfers_success_rateofinterest)
    TextView liveTransfersSuccessRateofinterest;
    @BindView(R.id.live_transfers_success_time)
    TextView liveTransfersSuccessTime;
    @BindView(R.id.live_transfers_success_isunloading)
    TextView liveTransfersSuccessIsunloading;
    @BindView(R.id.live_transfers_zc_rlayout)
    RelativeLayout liveTransfersZcRlayout;
    @BindView(R.id.live_transfers_success_updata)
    TextView liveTransfersSuccessUpdata;
    @BindView(R.id.live_transfers_success_nobtn)
    Button liveTransfersSuccessNobtn;
    @BindView(R.id.live_transfers_success_okbtn)
    Button liveTransfersSuccessOkbtn;
    @BindView(R.id.live_transfers_success_layout)
    CardView liveTransfersSuccessLayout;
    @BindView(R.id.connected_to_no_btn)
    Button connectedToNoBtn;
    @BindView(R.id.connected_to_yes_btn)
    Button connectedToYesBtn;
    @BindView(R.id.connected_to_layout)
    LinearLayout connectedToLayout;
    @BindView(R.id.sure_switchinfo_numtext)
    TextView sureSwitchinfoNumtext;
    @BindView(R.id.sure_switchinfo_moneytext)
    TextView sureSwitchinfoMoneytext;
    @BindView(R.id.sure_switchinfo_type)
    TextView sureSwitchinfoType;
    @BindView(R.id.sure_switchinfo_name)
    TextView sureSwitchinfoName;
    @BindView(R.id.sure_switchinfo_rate)
    TextView sureSwitchinfoRate;
    @BindView(R.id.sure_switchinfo_valuedate)
    TextView sureSwitchinfoValuedate;
    @BindView(R.id.sure_switchinfo_nobtn)
    Button sureSwitchinfoNobtn;
    @BindView(R.id.sure_switchinfo_yesbtn)
    Button sureSwitchinfoYesbtn;
    @BindView(R.id.sure_switchinfo_layout)
    CardView sureSwitchinfoLayout;
    @BindView(R.id.switch_success_usernum)
    TextView switchSuccessUsernum;
    @BindView(R.id.switch_success_money)
    TextView switchSuccessMoney;
    @BindView(R.id.switch_success_dealtype)
    TextView switchSuccessDealtype;
    @BindView(R.id.switch_success_time)
    TextView switchSuccessTime;
    @BindView(R.id.switch_success_interest)
    TextView switchSuccessInterest;
    @BindView(R.id.switch_success_upday)
    TextView switchSuccessUpday;
    @BindView(R.id.switch_success_stopday)
    TextView switchSuccessStopday;
    @BindView(R.id.switch_success_nobtn)
    Button switchSuccessNobtn;
    @BindView(R.id.switch_success_okbtn)
    Button switchSuccessOkbtn;
    @BindView(R.id.switch_success_layout)
    CardView switchSuccessLayout;
    private int num;
    private String jf_type;
    private PosFuncs posFuncs;
    private String[] yd_namas;
    private String ht_num;
    String Card_type = "";
    String s_number = "";
    String track2Data = "";
    String track3Data = "";
    private String pass_word;
    String Field55 = "";
    private String bindNum;
    private String rwNUm;
    private String time;
    private String pz_nums;
    String make_type = "";
    private String lt_name;
    private String jgh;
    private List<Select_subaccount_Bean> beans;
    int f59num = 0;
    private String dqzh;
    private String dxr;
    private String name;
    private boolean f59_dq = false;
    private String f59data;
    private Select_subaccount_adapter adapter;
    private int positions;
    private String qxr1;
    private String dxr1;
    private String f122_3;
    private String f122_4;
    private String lx;
    private String cq;
    private String f39;
    private String run_time;
    private String username;
    private int sb_num;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_charge_agency);
        ButterKnife.bind(this);
        this.setBackBtClick(R.id.base_back_btn);
        this.setTitleText(R.id.base_title_text, "(   " + "代理缴费" + "   )");
        liveToAtfixedperiodBtn.setText("惠农赢签约");
        atfixedperiodToLiveBtn.setText("惠农赢解约");
        handler = new Handler();
        posFuncs = PosFuncs.getInstace();
        posFuncs.init(this);

    }

    @OnClick({
            R.id.charge_agency_payment, R.id.charge_agency_Wisdomtosave,
            R.id.charge_agency_Unicompayment, R.id.charge_agency_hnwin,
            R.id.input_phone_nobtn, R.id.input_phone_okbtn,
            R.id.sure_printingpeper_okbtn,
            R.id.input_recharge_amount_noBtn,
            R.id.input_recharge_amount_yesBtn, R.id.topup_success_btn,
            R.id.sure_payment_noBtn, R.id.sure_payment_yesBtn,
            R.id.select_pay_type_xj_btn, R.id.select_pay_type_bank_btn,
            R.id.live_to_atfixedperiod_btn, R.id.atfixedperiod_to_live_btn,
            R.id.input_customanager_gzbtn, R.id.input_customanager_okbtn,
            R.id.hny_info_gzbtn, R.id.hny_info_okbtn,
            R.id.input_money_gzbtn, R.id.input_money_okbtn,
            R.id.live_transfers_success_nobtn,

            R.id.live_transfers_success_okbtn,
            R.id.connected_to_no_btn,

            R.id.connected_to_yes_btn,
            R.id.sure_switchinfo_nobtn,


            R.id.sure_switchinfo_yesbtn,
            R.id.switch_success_nobtn,

            R.id.switch_success_okbtn,

    })
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.charge_agency_payment:
                //移动缴费
                chargeAgencyLayout.setVisibility(View.GONE);
                inputPhoneNumLayout.setVisibility(View.VISIBLE);
                make_type = "yd";
                break;
            case R.id.charge_agency_Wisdomtosave:
                //智慧存
                Intent intent = new Intent(getApplicationContext(), Wisdomtosave_Activity.class);
                startActivity(intent);
                break;
            case R.id.charge_agency_Unicompayment:
                //联通缴费
                chargeAgencyLayout.setVisibility(View.GONE);
                inputPhoneNumLayout.setVisibility(View.VISIBLE);
                make_type = "lt";
                break;
            case R.id.charge_agency_hnwin:
                //惠农赢
                chargeAgencyLayout.setVisibility(View.GONE);
                liveTransfersLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.input_phone_nobtn:
                //输入手机号码 更正
                inputPhoneEdtext.setText("");
                break;
            case R.id.input_phone_okbtn:
                //输入手机号码 确认
                if (inputPhoneEdtext.getText().toString().trim().equals("")) {
                    Toast.makeText(this, "请输入手机号码", Toast.LENGTH_SHORT).show();
                } else {
                    if (inputPhoneEdtext.getText().toString().trim().length() == 11) {
                        inputPhoneNumLayout.setVisibility(View.GONE);
                        dealingLayout.setVisibility(View.VISIBLE);
                        new Thread(new Runnable() {
                            @Override
                            public void run() {

                                num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0);
                                Logger.e("第一次获取" + num);
                                if (make_type.equals("yd")) {
                                    excuteYDS(String.valueOf(num), inputPhoneEdtext.getText().toString().trim());
                                } else {
                                    excuteLTS(String.valueOf(num), inputPhoneEdtext.getText().toString().trim());
                                }
                                SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", num + 1);
                                Logger.e("第二次获取" + SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 1000));


                            }
                        }).start();
                    } else {
                        Toast.makeText(this, "请输入正确的手机号", Toast.LENGTH_SHORT).show();
                    }

                }
                break;
            case R.id.input_recharge_amount_noBtn:
                //输入充值金额 更正
                inputRechargeAmountEdtext.setText("");
                break;
            case R.id.input_recharge_amount_yesBtn:
                //输入充值金额 确定
                if (inputRechargeAmountEdtext.getText().toString().equals("")) {
                    Toast.makeText(this, "请输入充值金额", Toast.LENGTH_SHORT).show();
                } else {
                    if (make_type.equals("lt") || make_type.equals("yd")) {
                        inputRechargeAmountLayout.setVisibility(View.GONE);
                        selectPayTypeLayout.setVisibility(View.VISIBLE);
                    }
                }
                break;
//            case R.id.please_input_iccard_okbtn:
//                //已插入卡
//                pleaseInputIccardLayout.setVisibility(View.GONE);
//                ficationingLayout.setVisibility(View.VISIBLE);
//                runnable = new Runnable() {
//                    @Override
//                    public void run() {
//                        ficationingLayout.setVisibility(View.GONE);
//                        surePaymentPhonenum.setText(inputPhoneEdtext.getText().toString());
//                        surePaymentMoney.setText(inputRechargeAmountEdtext.getText().toString() + "元");
//                        surePaymentLayout.setVisibility(View.VISIBLE);
//                    }
//                };
//                handler.postDelayed(runnable, 300);
//                break;
            case R.id.sure_payment_noBtn:
                //确认支付 取消
                this.finish();
                break;
            case R.id.sure_payment_yesBtn:
                //确认支付 确定


//                    enterPin(bindNum, d * 100);
                if (jf_type.equals("1")) {
                    dealingLayout.setVisibility(View.VISIBLE);
                    surePaymentLayout.setVisibility(View.GONE);
                    if (inputRechargeAmountEdtext.getText().toString().contains(".")) {
                        DecimalFormat df = new DecimalFormat("######0.00");
                        Double d = Double.parseDouble(inputRechargeAmountEdtext.getText().toString().trim());
                        df.format(d);
                        enterPin(Constants.DEMO_F102, d * 100);
                    } else {
                        enterPin(Constants.DEMO_F102, Integer.parseInt(inputRechargeAmountEdtext.getText().toString().trim()) * 100);

                    }

                } else {
                    pleaseInputIccardLayout.setVisibility(View.VISIBLE);
                    surePaymentLayout.setVisibility(View.GONE);
                    if (inputRechargeAmountEdtext.getText().toString().contains(".")) {
                        DecimalFormat df = new DecimalFormat("######0.00");
                        Double d = Double.parseDouble(inputRechargeAmountEdtext.getText().toString().trim());
                        df.format(d);
                        tradeWithCards(d * 100);
                    } else {
                        tradeWithCards(Integer.parseInt(inputRechargeAmountEdtext.getText().toString().trim()) * 100);
                    }
                }
                break;
            case R.id.topup_success_btn:
                topupSuccessLayout.setVisibility(View.GONE);
//                inputRechargeAmountEdtext.setText("");
//                inputPhoneEdtext.setText("");
//                topupSuccessNum.setText("");
//                topupSuccessTime.setText("");
//                topupSuccessType.setText("");
//                topupSuccessTypesey.setText("");
//                surePaymentPhonenum.setText("");
//                surePaymentMoney.setText("");
//                inputRechargeAmountPhoneNum.setText("");
//                inputRechargeAmountType.setText("");
//                inputRechargeAmountBalance.setText("");
//                chargeAgencyLayout.setVisibility(View.VISIBLE);
                surePrintingpeperLayout.setVisibility(View.VISIBLE);
                //充值成功 确认
                break;
            case R.id.select_pay_type_xj_btn:
                //选择现金缴费
                jf_type = "1";
                selectPayTypeLayout.setVisibility(View.GONE);
                surePaymentLayout.setVisibility(View.VISIBLE);
                surePaymentMoney.setText(inputRechargeAmountEdtext.getText().toString().trim());
                surePaymentPhonenum.setText(inputPhoneEdtext.getText().toString().trim());

                break;
            case R.id.select_pay_type_bank_btn:
                //选择其他账户缴费
                jf_type = "2";
                selectPayTypeLayout.setVisibility(View.GONE);
                surePaymentLayout.setVisibility(View.VISIBLE);
                surePaymentMoney.setText(inputRechargeAmountEdtext.getText().toString().trim());
                surePaymentPhonenum.setText(inputPhoneEdtext.getText().toString().trim());
                break;
            case R.id.sure_printingpeper_okbtn:
                surePrintingpeperLayout.setVisibility(View.GONE);
                printingLayout.setVisibility(View.VISIBLE);

                if (make_type.equals("hnyqy")) {
                    paintHNYQY();
                } else if (make_type.equals("hnyjy")) {
                    paintHNYJY();
                } else {
                    paint();
                }
                break;
            case R.id.live_to_atfixedperiod_btn:
                //惠农赢签约
                make_type = "hnyqy";
                liveTransfersLayout.setVisibility(View.GONE);
                pleaseInputIccardLayout.setVisibility(View.VISIBLE);
                readCardTest();

                break;
            case R.id.atfixedperiod_to_live_btn:
                //惠农赢解约
                sb_num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0) + 1;

                make_type = "hnyjy";
                liveTransfersLayout.setVisibility(View.GONE);
                pleaseInputIccardLayout.setVisibility(View.VISIBLE);
                tradeWithCards(0);
                break;
            case R.id.input_customanager_gzbtn:
                //客户经理号更正
                inputCustomanagerEdtext.setText("");
                break;
            case R.id.input_customanager_okbtn:
                //客户经理号 确定
                //输入客户经理号 确定
                if (inputCustomanagerEdtext.getText().toString().equals("")) {
                    Toast.makeText(this, "请输入客户经理号", Toast.LENGTH_SHORT).show();

                } else if (inputCustomanagerEdtext.getText().toString().length() != 7) {
                    Toast.makeText(this, "请输入正确的客户经理号", Toast.LENGTH_SHORT).show();
                } else {
                    inputCustomanagerLayout.setVisibility(View.GONE);
                    inputMoneyLayout.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.hny_info_gzbtn:
                //惠农赢数据 取消
                this.finish();
                break;
            case R.id.hny_info_okbtn:
                //惠农赢数据 确定
                DecimalFormat df = new DecimalFormat("######0.00");
                if (inputMoneyEdtext.getText().toString().contains(".")) {
                    inputMoneyOkbtn.setClickable(false);
                    Double d = Double.parseDouble(inputMoneyEdtext.getText().toString().trim());
                    df.format(d);
                    tradeWithCards(d * 100);
                    hnyInfoLayout.setVisibility(View.GONE);
                    dealingLayout.setVisibility(View.VISIBLE);
                } else {
                    inputMoneyOkbtn.setClickable(false);
                    tradeWithCards(Integer.parseInt(inputMoneyEdtext.getText().toString().trim()) * 100);
                    hnyInfoLayout.setVisibility(View.GONE);
                    dealingLayout.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.input_money_gzbtn:
                //输入金额更正
                inputMoneyEdtext.setText("");
                break;
            case R.id.input_money_okbtn:
                //输入金额确定
                if (!inputMoneyEdtext.getText().toString().equals("")) {
                    if (inputMoneyEdtext.getText().toString().contains(".")) {
                        String mons[] = inputMoneyEdtext.getText().toString().split("\\.");
                        if (mons[1].length() > 2) {
                            Toast.makeText(this, "请输入正确的金额", Toast.LENGTH_SHORT).show();
                        } else {
                            inputMoneyLayout.setVisibility(View.GONE);
                            hnyInfoLayout.setVisibility(View.VISIBLE);
                            hnyInfoNum.setText(bindNum);
                            hnyInfoMoney.setText(inputMoneyEdtext.getText().toString());
                        }
//                        enterPin(bindNum, d * 100);
                    } else {
                        inputMoneyLayout.setVisibility(View.GONE);
                        hnyInfoLayout.setVisibility(View.VISIBLE);
                        hnyInfoNum.setText(bindNum);
                        hnyInfoMoney.setText(inputMoneyEdtext.getText().toString());
                    }
                } else {
                    Toast.makeText(this, "请输入金额！", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.live_transfers_success_nobtn:
                //惠农赢签约成功 取消
                this.finish();
                break;
            case R.id.live_transfers_success_okbtn:
                //惠农赢签约成功 确定
                liveTransfersSuccessLayout.setVisibility(View.GONE);
                chargeAgencyHomeLayout.setVisibility(View.VISIBLE);
                surePrintingpeperLayout.setVisibility(View.VISIBLE);

                break;
            case R.id.connected_to_no_btn:
                //联网查询 取消
                this.finish();
                break;
            case R.id.connected_to_yes_btn:
                //联网查询 确定
                chargeAgencyHomeLayout.setVisibility(View.GONE);
                sureSwitchinfoNumtext.setText(bindNum);
                sureSwitchinfoName.setText(beans.get(positions).getName() + "");
                sureSwitchinfoMoneytext.setText(beans.get(positions).getBalanceofAccount());
                sureSwitchinfoRate.setText(beans.get(positions).getRateofinterest());
                sureSwitchinfoValuedate.setText(beans.get(positions).getValuedate());
                sureSwitchinfoType.setText("惠农赢解约");
                sureSwitchinfoLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.sure_switchinfo_nobtn:
                //解约信息取消
                this.finish();
                break;
            case R.id.sure_switchinfo_yesbtn:
                //解约信息确定
                connectedToLayout.setVisibility(View.GONE);
                sureSwitchinfoLayout.setVisibility(View.GONE);
                chargeAgencyHomeLayout.setVisibility(View.VISIBLE);
                dealingLayout.setVisibility(View.VISIBLE);
                new Thread(new Runnable() {
                    @Override
                    public void run() {

                        run_time = DateUtil.getCurrentTime(DateUtil.M_TIME_PATTERN);

                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");// HH:mm:ss
                        //获取当前时间
                        Date date = new Date(System.currentTimeMillis());
                        time = simpleDateFormat.format(date);
                        num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0);
                        Logger.e("第一次获取rz" + num + Card_type);
                        enterDZH(String.valueOf(num));
                        SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", num + 1);
                        Logger.e("第二次获取rz" + SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0));
                    }
                }).start();

                break;
            case R.id.switch_success_nobtn:
//              解约成功取消
                this.finish();
                break;
            case R.id.switch_success_okbtn:
                //解约成功确定
                dealingLayout.setVisibility(View.GONE);
                switchSuccessLayout.setVisibility(View.GONE);
                chargeAgencyHomeLayout.setVisibility(View.VISIBLE);
                surePrintingpeperLayout.setVisibility(View.VISIBLE);
                break;
        }

    }

    /**
     * 读取卡
     */
    private void readCardTest() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                posFuncs.cardReaderConfig(true, true, true);

                posFuncs.emvSimpleFlow(new PosCallbacks.EmvTransStartCallbacks() {
                    @Override
                    public void onDetectCard(String type) {
                        Card_type = type;
                        Log.e("", type);
                    }

                    @Override
                    public void onConfirmCardInfo(String pan) {
                        Logger.e("pan" + pan);
                        bindNum = pan;
                        if (bindNum.equals("")) {
                            Toast.makeText(ChargeAgencyActivity.this, "请插入卡", Toast.LENGTH_SHORT).show();
                        } else {

                            Toast.makeText(getApplicationContext(), pan, Toast.LENGTH_SHORT).show();
                            posFuncs.emvConfirmCardInfo(EmvConstants.CONFIRM_OK);

                        }
                    }

                    @Override
                    public void onOlinePinEntered(String enc, boolean is_no_pin) {

                    }

                    @Override
                    public void onSuccess(Bundle data) {
                        if (!data.isEmpty()) {
                            pleaseInputIccardLayout.setVisibility(View.GONE);
                            ficationingLayout.setVisibility(View.VISIBLE);

                            Log.e("", data.getString(EmvConstants.FEILD_55));
                            //如果是磁条卡，就获取二磁信息、上传给银行接口
                            // IC Card    MAG Card    RF Card
                            if (Card_type.equals("MAG Card")) {
                                track2Data = data.getString(EmvConstants.TRACK2);
                                track3Data = data.getString(EmvConstants.TRACK3);

                            } else {
                                track2Data = Utils.formatField57(Utils.getValueFromIccData("57", data.getString(EmvConstants.FEILD_55)));
                                s_number = Utils.getValueFromIccData("5f34", data.getString(EmvConstants.FEILD_55));
                                String[] tags =
                                        {
                                                "9F26", "9F27", "9F10", "9F37", "9F36", "95",
                                                "9A", "9C", "9F02", "5F2A", "82", "9F1A", "9F03", "9F33", "9F34", "9F35",
                                                "9F1E", "84", "9F09", "9F41"
                                        };
                                Field55 = Utils.getField55(tags, data.getString(EmvConstants.FEILD_55));
                                Logger.e("f55" + Field55);
                                Logger.e(s_number + "s_numbers_number");
                            }
                            new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0);
                                    Logger.e("第一次获取rz" + num);
                                    excuteVTA(String.valueOf(num), bindNum, Card_type, track2Data);
                                    SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", num + 1);
                                    Logger.e("第二次获取rz" + SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0));
                                }
                            }).start();
                        }

                    }

                    @Override
                    public void onFailed(String error) {
                        Toast.makeText(ChargeAgencyActivity.this, error, Toast.LENGTH_SHORT).show();
                    }
                });
            }
        }).start();
    }

    /**
     * 定转活打印
     */
    private void paintHNYJY() {
        new Thread() {
            @Override
            public void run() {
                super.run();
                posFuncs.printerClearBuffer();
                posFuncs.printerAppendLargeTextAlignCenter("烟台银行 通用凭证");

                posFuncs.printerAppendTextline("交易时间 :" + time);
                posFuncs.printerAppendTextline("设备号 :" + Constants.YANTAI_TERMNO);
                posFuncs.printerAppendTextline("操作员 :" + SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""));
                posFuncs.printerAppendTextline("转出账号 :" + bindNum);

                posFuncs.printerAppendTextline("流水号 :" + rwNUm);

                posFuncs.printerAppendTextline("业务类型 :定期转活期");
                posFuncs.printerAppendTextline("户名 :" + name);

                posFuncs.printerAppendTextline("金额 :" + beans.get(positions).getBalanceofAccount() + ".00");
                posFuncs.printerAppendTextline("定期子号 :" + beans.get(positions).getNum());
                posFuncs.printerAppendTextline("存款种类 :" + beans.get(positions).getName());
                posFuncs.printerAppendTextline("存期 :" + cq + "天");
                posFuncs.printerAppendTextline("利息 :" + lx);
                posFuncs.printerAppendTextline("起息日 :" + beans.get(positions).getValuedate());
                posFuncs.printerAppendTextline("到期日 :" + beans.get(positions).getDuedate());
//                posFuncs.printerAppendTextline("本息合计 :");
                posFuncs.printerAppendTextline("凭证序号 :" + pz_nums);
                posFuncs.printerAppendTextline("客户签字确认 :");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("--------------------------------------");
                posFuncs.printerAppendLargeTextAlignCenter("烟台银行 通用凭证");
                posFuncs.printerAppendTextline("交易时间 :" + time);
                posFuncs.printerAppendTextline("设备号 :" + Constants.YANTAI_TERMNO);
                posFuncs.printerAppendTextline("操作员 :" + SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""));
                String bindx = bindNum.substring(6, bindNum.length() - 5);
                String bindxs = "*";
                for (int i = 0; i < bindx.length(); i++) {
                    bindxs = bindxs + "*";
                }
                posFuncs.printerAppendTextline("转出账号 :" + bindNum.substring(0, 6) + bindxs + bindNum.substring(bindNum.length() - 4, bindNum.length()));

                posFuncs.printerAppendTextline("流水号 :" + rwNUm);

                posFuncs.printerAppendTextline("业务类型 :定期转活期");
                String RemittanceNameone = name.substring(0, 1);
                posFuncs.printerAppendTextline("户名 :" + name.replaceFirst(RemittanceNameone, "*"));


                posFuncs.printerAppendTextline("金额 :" + beans.get(positions).getBalanceofAccount() + ".00");
                posFuncs.printerAppendTextline("定期子号 :" + beans.get(positions).getNum());
                posFuncs.printerAppendTextline("存款种类 :" + beans.get(positions).getName());
                posFuncs.printerAppendTextline("存期 :" + cq + "天");
                posFuncs.printerAppendTextline("利息 :" + lx);
                posFuncs.printerAppendTextline("起息日 :" + beans.get(positions).getValuedate());
                posFuncs.printerAppendTextline("到期日 :" + beans.get(positions).getDuedate());
//                posFuncs.printerAppendTextline("本息合计 :");
                posFuncs.printerAppendTextline("凭证序号 :" + pz_nums);
                posFuncs.printerAppendTextline("客户签字确认 :");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");


                posFuncs.startPrint(new PosCallbacks.PrintCallbacaks() {
                    @Override
                    public void onSuccess() {
                        Toast.makeText(ChargeAgencyActivity.this, "打印成功", Toast.LENGTH_SHORT).show();
                        SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", sb_num + f59num);
                      Logger.e( sb_num +"     "+ f59num);
                        finish();

                    }

                    @Override
                    public void onFailed(String error) {
                        if (error.equals("Lack Paper")) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(ChargeAgencyActivity.this, "请确认打印纸安装正确", Toast.LENGTH_SHORT).show();
                                    surePrintingpeperLayout.setVisibility(View.VISIBLE);
                                    printingLayout.setVisibility(View.GONE);
                                }
                            });
                        }
                    }
                });
            }
        }.start();
    }

    private void paintHNYQY() {
        new Thread() {
            @Override
            public void run() {
                super.run();
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");// HH:mm:ss
                Date date = new Date(System.currentTimeMillis());
                posFuncs.printerClearBuffer();
                posFuncs.printerAppendLargeTextAlignCenter("烟台银行 通用凭证");
                posFuncs.printerAppendTextline("交易时间 :" + time);
                posFuncs.printerAppendTextline("设备号 :" + Constants.YANTAI_TERMNO);
                posFuncs.printerAppendTextline("操作员 :" + SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""));
                posFuncs.printerAppendTextline("账号 :" + bindNum);


                posFuncs.printerAppendTextline("业务类型 :" + "活期转定期惠农赢签约");
                posFuncs.printerAppendTextline("户名 :" + name);


                if (inputMoneyEdtext.getText().toString().contains(".")) {
                    String moneys[] = inputMoneyEdtext.getText().toString().split("\\.");
                    if (moneys[1].length() == 1) {
                        String monses = moneys[0] + "." + moneys[1] + "0";
                        posFuncs.printerAppendTextline("金额 :" + monses);
                    } else {
                        posFuncs.printerAppendTextline("金额 :" + inputMoneyEdtext.getText().toString());
                    }

                } else {

                    posFuncs.printerAppendTextline("金额 :" + inputMoneyEdtext.getText().toString() + ".00");
                }

                posFuncs.printerAppendTextline("定期子号 :" + dqzh);


                posFuncs.printerAppendTextline("存款种类 :" + "惠农赢1号");
                posFuncs.printerAppendTextline("自动转存 :" + "否");


                posFuncs.printerAppendTextline("起息日 :" + simpleDateFormat.format(date).replace("/", ""));
                posFuncs.printerAppendTextline("到期日 :" + dxr);
                posFuncs.printerAppendTextline("凭证序号 :" + pz_nums);
                posFuncs.printerAppendTextline("客户签字确认 :");

                posFuncs.printerAppendTextline("--------------------------------------");
                posFuncs.printerAppendLargeTextAlignCenter("烟台银行 通用凭证");
                posFuncs.printerAppendTextline("交易时间 :" + time);
                posFuncs.printerAppendTextline("设备号 :" + Constants.YANTAI_TERMNO);
                posFuncs.printerAppendTextline("操作员 :" + SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""));

                String bindx = bindNum.substring(6, bindNum.length() - 5);
                String bindxs = "*";
                for (int i = 0; i < bindx.length(); i++) {
                    bindxs = bindxs + "*";
                }
                posFuncs.printerAppendTextline("账号 :" + bindNum.substring(0, 6) + bindxs + bindNum.substring(bindNum.length() - 4, bindNum.length()));

                posFuncs.printerAppendTextline("业务类型 :" + "活期转定期惠农赢签约");
                String RemittanceNameone = name.substring(0, 1);
                posFuncs.printerAppendTextline("户名 :" + name.replaceFirst(RemittanceNameone, "*"));


                if (inputMoneyEdtext.getText().toString().contains(".")) {
                    String moneys[] = inputMoneyEdtext.getText().toString().split("\\.");
                    if (moneys[1].length() == 1) {
                        String monses = moneys[0] + "." + moneys[1] + "0";
                        posFuncs.printerAppendTextline("金额 :" + monses);
                    } else {
                        posFuncs.printerAppendTextline("金额 :" + inputMoneyEdtext.getText().toString());
                    }

                } else {

                    posFuncs.printerAppendTextline("金额 :" + inputMoneyEdtext.getText().toString() + ".00");
                }

                posFuncs.printerAppendTextline("定期子号 :" + dqzh);


                posFuncs.printerAppendTextline("存款种类 :" + "惠农赢1号");
                posFuncs.printerAppendTextline("自动转存 :" + "否");


                posFuncs.printerAppendTextline("起息日 :" + simpleDateFormat.format(date).replace("/", ""));
                posFuncs.printerAppendTextline("到期日 :" + dxr);
                posFuncs.printerAppendTextline("凭证序号 :" + pz_nums);
                posFuncs.printerAppendTextline("客户签字确认 :");

                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");


                posFuncs.startPrint(new PosCallbacks.PrintCallbacaks() {
                    @Override
                    public void onSuccess() {
                        Toast.makeText(ChargeAgencyActivity.this, "打印成功", Toast.LENGTH_SHORT).show();
                        finish();
                    }

                    @Override
                    public void onFailed(String error) {
                        if (error.equals("Lack Paper")) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(ChargeAgencyActivity.this, "请确认打印纸安装正确", Toast.LENGTH_SHORT).show();
                                    surePrintingpeperLayout.setVisibility(View.VISIBLE);
                                    printingLayout.setVisibility(View.GONE);
                                }
                            });
                        }
                    }
                });
            }
        }.start();
    }

    private void paint() {
        new Thread() {
            @Override
            public void run() {
                super.run();
                posFuncs.printerClearBuffer();
                posFuncs.printerAppendLargeTextAlignCenter("烟台银行 通用凭证");
                posFuncs.printerAppendTextline("交易时间 :" + time);
                posFuncs.printerAppendTextline("设备号 :" + Constants.YANTAI_TERMNO);
                posFuncs.printerAppendTextline("操作员 :" + SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""));
                if (jf_type.equals("1")) {
                    posFuncs.printerAppendTextline("缴费账号 :" + Constants.DEMO_F102);
                } else {
                    posFuncs.printerAppendTextline("缴费账号 :" + bindNum);
                }

                posFuncs.printerAppendTextline("缴费号码 :" + inputPhoneEdtext.getText().toString().trim());

                posFuncs.printerAppendTextline("流水号 :" + rwNUm);
                if (make_type.equals("yd")) {
                    posFuncs.printerAppendTextline("业务类型 :" + "移动缴费");

                } else {
                    posFuncs.printerAppendTextline("业务类型 :" + "联通缴费");
                }
                if (inputRechargeAmountEdtext.getText().toString().contains(".")) {
                    String moneys[] = inputRechargeAmountEdtext.getText().toString().split("\\.");
                    if (moneys[1].length() == 1) {
                        String monses = moneys[0] + "." + moneys[1] + "0";
                        posFuncs.printerAppendTextline("缴费金额 :" + monses);
                    } else {
                        posFuncs.printerAppendTextline("缴费金额 :" + inputRechargeAmountEdtext.getText().toString());
                    }

                } else {

                    posFuncs.printerAppendTextline("缴费金额 :" + inputRechargeAmountEdtext.getText().toString() + ".00");
                }
                if (jf_type.equals("1")) {
                    posFuncs.printerAppendTextline("缴费方式 :" + "现金支付");

                } else {
                    posFuncs.printerAppendTextline("缴费方式 :" + "转账缴费");
                }
                posFuncs.printerAppendTextline("凭证序号 :" + pz_nums);

                posFuncs.printerAppendTextline("客户签字确认 :");

                posFuncs.printerAppendTextline("--------------------------------------");
                posFuncs.printerAppendLargeTextAlignCenter("烟台银行 通用凭证");
                posFuncs.printerAppendTextline("交易时间 :" + time);
                posFuncs.printerAppendTextline("设备号 :" + Constants.YANTAI_TERMNO);
                posFuncs.printerAppendTextline("操作员 :" + SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""));
                if (jf_type.equals("1")) {
                    String bindx = Constants.DEMO_F102.substring(6, Constants.DEMO_F102.length() - 5);
                    String bindxs = "*";
                    for (int i = 0; i < bindx.length(); i++) {
                        bindxs = bindxs + "*";
                    }
                    posFuncs.printerAppendTextline("缴费账号 :" + Constants.DEMO_F102.substring(0, 6) + bindxs + Constants.DEMO_F102.substring(Constants.DEMO_F102.length() - 4, Constants.DEMO_F102.length()));

                } else {
                    String bindx = bindNum.substring(6, bindNum.length() - 5);
                    String bindxs = "*";
                    for (int i = 0; i < bindx.length(); i++) {
                        bindxs = bindxs + "*";
                    }
                    posFuncs.printerAppendTextline("缴费账号 :" + bindNum.substring(0, 6) + bindxs + bindNum.substring(bindNum.length() - 4, bindNum.length()));

                }


                posFuncs.printerAppendTextline("缴费号码 :" + inputPhoneEdtext.getText().toString().trim());

                posFuncs.printerAppendTextline("流水号 :" + rwNUm);
                if (make_type.equals("yd")) {
                    posFuncs.printerAppendTextline("业务类型 :" + "移动缴费");

                } else {
                    posFuncs.printerAppendTextline("业务类型 :" + "联通缴费");
                }
                if (inputRechargeAmountEdtext.getText().toString().contains(".")) {
                    String moneys[] = inputRechargeAmountEdtext.getText().toString().split("\\.");
                    if (moneys[1].length() == 1) {
                        String monses = moneys[0] + "." + moneys[1] + "0";
                        posFuncs.printerAppendTextline("缴费金额 :" + monses);
                    } else {
                        posFuncs.printerAppendTextline("缴费金额 :" + inputRechargeAmountEdtext.getText().toString());
                    }

                } else {

                    posFuncs.printerAppendTextline("缴费金额 :" + inputRechargeAmountEdtext.getText().toString() + ".00");
                }
                if (jf_type.equals("1")) {
                    posFuncs.printerAppendTextline("缴费方式 :" + "现金支付");

                } else {
                    posFuncs.printerAppendTextline("缴费方式 :" + "转账缴费");
                }
                posFuncs.printerAppendTextline("凭证序号 :" + pz_nums);
                posFuncs.printerAppendTextline("客户签字确认 :");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");
                posFuncs.printerAppendTextline("");


                posFuncs.startPrint(new PosCallbacks.PrintCallbacaks() {
                    @Override
                    public void onSuccess() {
                        Toast.makeText(ChargeAgencyActivity.this, "打印成功", Toast.LENGTH_SHORT).show();
                        finish();
                    }

                    @Override
                    public void onFailed(String error) {
                        if (error.equals("Lack Paper")) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(ChargeAgencyActivity.this, "请确认打印纸安装正确", Toast.LENGTH_SHORT).show();
                                    surePrintingpeperLayout.setVisibility(View.VISIBLE);
                                    printingLayout.setVisibility(View.GONE);
                                }
                            });
                        }
                    }
                });
            }
        }.start();
    }

    private void tradeWithCards(final double money) {
        Logger.e(money + "");
        PinPad.initPinPad(posFuncs);
        new Thread() {
            @Override
            public void run() {

                posFuncs.cardReaderConfig(true, true, true);
                posFuncs.emvTransStart(new PosCallbacks.EmvTransStartCallbacks() {

                    @Override
                    public void onDetectCard(String type) {
                        Card_type = type;
                    }

                    @Override
                    public void onConfirmCardInfo(final String pan) {
                        bindNum = pan;
                        posFuncs.emvConfirmCardInfo(EmvConstants.CONFIRM_OK);
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                pleaseInputIccardLayout.setVisibility(View.GONE);
                                dealingLayout.setVisibility(View.VISIBLE);
                            }
                        });

                    }

                    @Override
                    public void onOlinePinEntered(String enc, boolean is_no_pin) {
                        if (!is_no_pin) {

                            try {
                                String pin = PinPad.getPin(bindNum, enc);
                                pass_word = pin;
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        } else {
                            Toast.makeText(getApplicationContext(), "请输入密码", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    public void onSuccess(Bundle data) {
                        String channel = data.getString(EmvConstants.CHANNEL);
                        if (EmvConstants.CHANNEL_MAGCARD.equals(channel)) {
//                            appendInfo("MagCard Used\n");
//                            appendInfo("Track1: " + data.getString(EmvConstants.TRACK1) + "\n");
//                            appendInfo("Track2: " + data.getString(EmvConstants.TRACK2) + "\n");
//                            appendInfo("Track3: " + data.getString(EmvConstants.TRACK3) + "\n");
//                            appendInfo("\nFinish\n");
//                            setEmvProcessStatus(false);
                        } else if (EmvConstants.CHANNEL_ICC.equals(channel)) {
//                            appendInfo("ICCard Used\n");
                            track2Data = Utils.formatField57(Utils.getValueFromIccData("57", data.getString(EmvConstants.FEILD_55)));
                            s_number = Utils.getValueFromIccData("5f34", data.getString(EmvConstants.FEILD_55));
                            String ac_type = data.getString(EmvConstants.AC_TYPE);
                            Logger.e("ac_type" + ac_type);
                            Logger.e("Ac Type: " + data.getString(EmvConstants.AC_TYPE) + "\n");
                            Logger.e("Field 55: " + data.getString(EmvConstants.FEILD_55) + "\n");
                            String[] tags =
                                    {
                                            "9F26", "9F27", "9F10", "9F37", "9F36", "95",
                                            "9A", "9C", "9F02", "5F2A", "82", "9F1A", "9F03", "9F33", "9F34", "9F35",
                                            "9F1E", "84", "9F09", "9F41"
                                    };
                            Field55 = Utils.getField55(tags, data.getString(EmvConstants.FEILD_55));
                            Logger.e("f55" + Field55);
                            if (EmvConstants.AC_TYPE_ARQC.equals(ac_type)) {

                                Bundle bundle = new Bundle();
                                bundle.putString(EmvConstants.RESPONSE_CODE, "3030");
                                posFuncs.emvOnlineResult(new PosCallbacks.EmvOnlineResultCallbacks() {
                                    @Override
                                    public void onSuccess(Bundle data) {
                                        Logger.e("Ac Type: " + data.getString(EmvConstants.AC_TYPE) + "\n");
                                        Logger.e("Field 55: " + data.getString(EmvConstants.FEILD_55) + "\n");

                                    }

                                    @Override
                                    public void onFailed(String error) {

                                    }
                                }, bundle);
                            } else {

                            }
                        } else if (EmvConstants.CHANNEL_ICCL.equals(channel)) {
                            Logger.e("Ac Type: " + data.getString(EmvConstants.AC_TYPE) + "\n");
                            Logger.e("Field 55: " + data.getString(EmvConstants.FEILD_55) + "\n");

                        }

                        new Thread(new Runnable() {
                            @Override
                            public void run() {
                                run_time = DateUtil.getCurrentTime(DateUtil.M_TIME_PATTERN);
                                num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0);
                                Logger.e("第一次获取" + num);
                                if (make_type.equals("yd")) {
                                    excuteYDJF(String.valueOf(num), inputPhoneEdtext.getText().toString().trim(), inputRechargeAmountEdtext.getText().toString(), bindNum);
                                } else if (make_type.equals("hnyqy")) {
                                    excutHNYQY(String.valueOf(num));
                                } else if (make_type.equals("hnyjy")) {
                                    excuteVTA(String.valueOf(num), bindNum, Card_type, track2Data);
                                } else {
                                    excuteLTJF(String.valueOf(num), inputPhoneEdtext.getText().toString().trim(), inputRechargeAmountEdtext.getText().toString(), bindNum);
                                }
                                SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", num + 1);
                                Logger.e("第二次获取" + SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 1000));

                            }
                        }).start();
                    }

                    @Override
                    public void onFailed(String error) {

                    }
                }, (int) money, 0);
            }
        }.start();
    }

    /**
     * 调取键盘
     */
    private void enterPin(final String bindNum, final double money) {
        Logger.e(money + "");
        new Thread() {
            @Override
            public void run() {
                posFuncs.enterPin(new PosCallbacks.EnterPinCallbacks() {
                    @Override
                    public void onSuccess(final String enc, boolean is_no_pin) {
                        if (is_no_pin) {
                        } else {
                            String pin = null;
                            try {
                                pin = PinPad.getPin(bindNum, enc);
                                pass_word = pin;
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            Log.e("", enc);
                            new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    run_time = DateUtil.getCurrentTime(DateUtil.M_TIME_PATTERN);
                                    num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0);
                                    Logger.e("第一次获取" + num);
                                    if (make_type.equals("yd")) {
                                        excuteYDJF(String.valueOf(num), inputPhoneEdtext.getText().toString().trim(), inputRechargeAmountEdtext.getText().toString(), bindNum);
                                    } else {
                                        excuteLTJF(String.valueOf(num), inputPhoneEdtext.getText().toString().trim(), inputRechargeAmountEdtext.getText().toString(), bindNum);
                                    }
                                    SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", num + 1);
                                    Logger.e("第二次获取" + SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 1000));

                                }
                            }).start();

                        }
                    }

                    @Override
                    public void onFail(String error) {
                        Toast.makeText(ChargeAgencyActivity.this, "交易结束", Toast.LENGTH_SHORT).show();
                        if (!error.equals(null)) {
                            finish();
                        }

                    }

                    @Override
                    public void onInput(int input_num) {
                        Log.e("", String.valueOf(input_num));
                    }
                }, bindNum, (int) money);
            }
        }.start();
    }

    /**
     * 惠农赢解约
     *
     * @param
     */
    private void enterDZH(String transn) {
        SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", sb_num + f59num);

        String c_bin_info = SpUtils.getSPUtil(getApplicationContext()).getString("c_bin_info", "null");
        Gson gson = new Gson();
        List<CardBinInfo_bean> beanss = gson.fromJson(c_bin_info, new TypeToken<List<CardBinInfo_bean>>() {
        }.getType());
        IsoMessage msg = null;
        LTFInterface inter = new LTFInterface();
        msg = inter.packRequest(bindNum, beanss, String.valueOf(sb_num + f59num-1), track2Data, track3Data, Card_type, pass_word, "1", Field55,
                beans.get(positions).getZhnum(), "369", "hnyjy", "0", inputCustomanagerEdtext.getText().toString(), jgh, "",
                beans.get(positions).getNum(), beans.get(positions).getBalanceofAccount(), s_number, run_time);
        excuteRequest(msg, "hnyjy");
    }

    /**
     * 账户验证
     */
    public void excuteVTA(String transn, String bindNum, String CardTYpe, String track2Data) {
        String c_bin_info = SpUtils.getSPUtil(getApplicationContext()).getString("c_bin_info", "null");
        Gson gson = new Gson();
        List<CardBinInfo_bean> beans = gson.fromJson(c_bin_info, new TypeToken<List<CardBinInfo_bean>>() {
        }.getType());
        IsoMessage msg = null;
        VTAInterface inter = new VTAInterface();
        msg = inter.packRequest(bindNum, beans, transn, track2Data, CardTYpe, String.valueOf(2), s_number);
        excuteRequest(msg, "zhrz");
    }

    /**
     * 移动查询余额
     */
    public void excuteYDS(String transn, String phone_num) {

        IsoMessage msg = null;
        YDSInstall inter = new YDSInstall();
        msg = inter.packRequest(transn, phone_num);
        excuteRequest(msg, "ydcx");
    }

    /**
     * 联通查询余额
     */
    public void excuteLTS(String transn, String phone_num) {

        IsoMessage msg = null;
        LTSInstall inter = new LTSInstall();
        msg = inter.packRequest(transn, phone_num);
        excuteRequest(msg, "ltcx");
    }

    /**
     * 移动缴费
     */
    public void excuteYDJF(String transn, String phone_num, String money, String bind_num) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");// HH:mm:ss

        Date date = new Date(System.currentTimeMillis());
        time = simpleDateFormat.format(date);
        IsoMessage msg = null;
        YDPInstall inter = new YDPInstall();
        msg = inter.packRequest(transn, phone_num, yd_namas[0], ht_num, bind_num,
                money, jf_type, Card_type, s_number, track2Data, track3Data, Field55, pass_word, run_time);
        excuteRequest(msg, "ydjf");
    }

    /**
     * 联通缴费
     */
    public void excuteLTJF(String transn, String phone_num, String money, String bind_num) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");// HH:mm:ss

        Date date = new Date(System.currentTimeMillis());
        time = simpleDateFormat.format(date);
        IsoMessage msg = null;
        LTPInstall inter = new LTPInstall();
        msg = inter.packRequest(transn, phone_num, lt_name, ht_num, bind_num,
                money, jf_type, Card_type, s_number, track2Data, track3Data, Field55, pass_word, run_time);
        excuteRequest(msg, "ltjf");
    }

    /**
     * 惠农赢签约
     */
    public void excutHNYQY(String transn) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");// HH:mm:ss

        Date date = new Date(System.currentTimeMillis());
        time = simpleDateFormat.format(date);
        String c_bin_info = SpUtils.getSPUtil(getApplicationContext()).getString("c_bin_info", "null");
        Gson gson = new Gson();
        List<CardBinInfo_bean> beans = gson.fromJson(c_bin_info, new TypeToken<List<CardBinInfo_bean>>() {
        }.getType());
        IsoMessage msg = null;
        HNYQInterface inter = new HNYQInterface();
        msg = inter.packRequest(bindNum, beans, transn, track2Data, track3Data,
                Card_type, pass_word, "1", Field55,
                jgh, inputCustomanagerEdtext.getText().toString(), inputMoneyEdtext.getText().toString(), s_number);
        excuteRequest(msg, "hnyqy");
    }

    /**
     * 已签约惠农赢1号查询
     */
    public void excuteSBA(String transn) {
        String c_bin_info = SpUtils.getSPUtil(getApplicationContext()).getString("c_bin_info", "null");
        Gson gson = new Gson();
        List<CardBinInfo_bean> beans = gson.fromJson(c_bin_info, new TypeToken<List<CardBinInfo_bean>>() {
        }.getType());
        IsoMessage msg = null;
        SBAhnInterface inter = new SBAhnInterface();
        msg = inter.packRequest(bindNum, beans, transn, track2Data, track3Data, pass_word, Card_type, String.valueOf(1), Field55, s_number, f59num, f59data);
        excuteRequest(msg, "zhcx");
    }

    private void excuteRequest(IsoMessage msg, final String op_type) {

        byte[] data = msg.writeData();
        // ��д����ͷ��7�򳤶�ֵ
        int hlen = Constants.ATMP_HEADER_LENGTH;
        int bodylen = data.length - hlen;
        String headF7 = ServiceCommon.appendZero(bodylen, 4);
        System.arraycopy(headF7.getBytes(), 0, data, 28, 4);
        // ����MAC
        if (msg.getField(128) != null) {
//            int start = hlen;
//            int length = data.length - start - 8;
//            byte[] inmac = new byte[length];
//            byte[] outmac = new byte[16];
//            System.arraycopy(data, start, inmac, 0, length);
//
//            Logger.e(Constants.YANTAI_MACKEY);
//            String mackey = Constants.YANTAI_MACKEY;
//            // MAC99�㷨makֻ��Ҫ16�ֽ���Կ
//            if (mackey.length() > 16) {
//                mackey = mackey.substring(0, 16);
//            }
//            DES3.getMacBlock_99(inmac, mackey.getBytes(), outmac);
//            System.arraycopy(outmac, 0, data, data.length - 8, 8);
            int start = hlen;
            int length = data.length - start - 8 ;
            byte[] inmac = new byte[length];
            byte[] outmac = new byte[16];
            System.arraycopy(data, start, inmac, 0, length);
            System.out.println("MAC数据=["+HexT.byteArr2HexStr(inmac)+"]");
            String mackey = Constants.YANTAI_MACKEY;

            if(Constants.isSM){
                // SM4 MAC919算法
                byte[] mkey = HexT.hexstr2ByteArr(mackey);
                String macval = SMS4.sms4MacBlock_919(inmac, mkey);
                outmac = macval.getBytes();
            }else{
                // MAC99算法mak只需要16字节密钥
                if(mackey.length()>16){
                    mackey = mackey.substring(0, 16);
                }
                DES3.getMacBlock_99(inmac, mackey.getBytes(), outmac);
            }

            System.arraycopy(outmac, 0, data, data.length-8, 8);
            System.out.println("请求MAC=["+new String(outmac).substring(0, 8)+"]");
        }
        byte[] send = null;
        // ���ļ��ܣ���������ʱ��ҵ���ױ��뱨�ļ���
        String encflag = msg.getHeadStringValue(4);
        if ("1".equals(encflag)) {
            String tdk = Constants.YANTAI_TDKKEY;
            int lenr = 8 - bodylen % 8;
            byte[] head = new byte[hlen];
            byte[] decdata = new byte[bodylen + lenr];
            System.arraycopy(data, 0, head, 0, hlen);
            System.arraycopy(data, hlen, decdata, 0, bodylen);
            byte[] encdata = DES3.des3Packet(decdata, tdk.getBytes());
            send = new byte[hlen + encdata.length];
            System.arraycopy(head, 0, send, 0, hlen);
            System.arraycopy(encdata, 0, send, hlen, encdata.length);

        }else if ("3".equals(encflag)){
            String tdk = Constants.YANTAI_TDKKEY;
            byte[] tdkey = HexT.hexstr2ByteArr(tdk);
            byte[] h7 = new byte[4];
            System.arraycopy(data, 28, h7, 0, 4);
            int orilen = Integer.parseInt(new String(h7));
            int enclen = data.length-Constants.ATMP_HEADER_LENGTH;
            byte[] head = new byte[Constants.ATMP_HEADER_LENGTH];
            byte[] encdata = new byte[enclen];
            System.arraycopy(data, 0, head, 0, Constants.ATMP_HEADER_LENGTH);
            System.arraycopy(data, Constants.ATMP_HEADER_LENGTH, encdata, 0, enclen);
            byte[] decdata = SMS4.unsms4Packet(encdata, tdkey);

            send = new byte[Constants.ATMP_HEADER_LENGTH+orilen];
            System.arraycopy(head, 0, send, 0, Constants.ATMP_HEADER_LENGTH);
            System.arraycopy(decdata, 0, send, Constants.ATMP_HEADER_LENGTH, orilen);
        } else {
            send = data;
        }

        CommAdapter adapter = new CommAdapter(Constants.IP, 3551);
        adapter.setHeadlen(4); // ����ͷ��4�ֽ�
        byte[] recv = adapter.doComm(send);

        byte[] recv2 = null;
        byte[] b = new byte[1];
        System.arraycopy(recv, 11, b, 0, 1);
        String rspenc = new String(b);

        if ("1".equals(rspenc)) {
            String tdk = Constants.YANTAI_TDKKEY;
            byte[] h7 = new byte[4];
            System.arraycopy(recv, 28, h7, 0, 4);
            int orilen = Integer.parseInt(new String(h7));
            int enclen = recv.length - Constants.ATMP_HEADER_LENGTH;
            byte[] head = new byte[Constants.ATMP_HEADER_LENGTH];
            byte[] encdata = new byte[enclen];
            System.arraycopy(recv, 0, head, 0, Constants.ATMP_HEADER_LENGTH);
            System.arraycopy(recv, Constants.ATMP_HEADER_LENGTH, encdata, 0, enclen);
            byte[] decdata = DES3.undes3Packet(encdata, tdk.getBytes());

            recv2 = new byte[Constants.ATMP_HEADER_LENGTH + orilen];
            System.arraycopy(head, 0, recv2, 0, Constants.ATMP_HEADER_LENGTH);
            System.arraycopy(decdata, 0, recv2, Constants.ATMP_HEADER_LENGTH, orilen);
        } else {
            recv2 = recv;
        }

        IsoMessage rsp = null;
        MessageFactory<IsoMessage> fac = new MessageFactory<IsoMessage>();
        try {
            rsp = fac.parseMessage(recv2, 32);
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        String respcode = rsp.getStringValue(39);
        if ("00".equals(respcode)) {
            unpackReSpone(rsp, op_type);

        } else if ("96".equals(respcode)) {
            Gson gson = new Gson();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");// HH:mm:ss
            //获取当前时间
            Date date = new Date(System.currentTimeMillis());
            Logger.e("Date获取当前日期时间" + simpleDateFormat.format(date).replace("/", "") + "UN_DATA");
            if (make_type.equals("yd")) {
                StatisticalData_bean bean = new StatisticalData_bean(rwNUm, inputRechargeAmountEdtext.getText().toString().trim(), time, "移动缴费", bindNum, yd_namas[0], SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""), pz_nums);
                String STAT_DATA = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", ""), "");

                List<StatisticalData_bean> beans = gson.fromJson(STAT_DATA, new TypeToken<List<StatisticalData_bean>>() {
                }.getType());
                beans.add(bean);
                SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "UN_DATA", gson.toJson(beans));

            } else if (make_type.equals("lt")) {
                StatisticalData_bean bean = new StatisticalData_bean(rwNUm, inputRechargeAmountEdtext.getText().toString().trim(), time, "联通缴费", bindNum, yd_namas[0], SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""), pz_nums);
                String STAT_DATA = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", ""), "");

                List<StatisticalData_bean> beans = gson.fromJson(STAT_DATA, new TypeToken<List<StatisticalData_bean>>() {
                }.getType());
                beans.add(bean);
                SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "UN_DATA", gson.toJson(beans));

            } else if (make_type.equals("hnyqy")) {
                StatisticalData_bean bean = new StatisticalData_bean(rwNUm, inputMoneyEdtext.getText().toString().trim(), time, "惠农赢签约", bindNum, yd_namas[0], SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""), pz_nums);
                String STAT_DATA = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", ""), "");

                List<StatisticalData_bean> beans = gson.fromJson(STAT_DATA, new TypeToken<List<StatisticalData_bean>>() {
                }.getType());
                beans.add(bean);
                SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "UN_DATA", gson.toJson(beans));

            } else if (make_type.equals("hnyjy")) {
                StatisticalData_bean bean = new StatisticalData_bean(rwNUm, inputRechargeAmountEdtext.getText().toString().trim(), time, "惠农赢解约", bindNum, yd_namas[0], SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""), pz_nums);
                String STAT_DATA = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", ""), "");

                List<StatisticalData_bean> beans = gson.fromJson(STAT_DATA, new TypeToken<List<StatisticalData_bean>>() {
                }.getType());
                beans.add(bean);
                SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "UN_DATA", gson.toJson(beans));

            }
            finish();
        } else {
            f39 = rsp.getStringValue(39);
            if (op_type.equals("hnyqy")) {
                Up_RundataUtils up_rundataUtils = new Up_RundataUtils();
                try {
                    up_rundataUtils.packRequest("0200", "440100",
                            inputMoneyEdtext.getText().toString().trim(), "1", run_time, String.valueOf(num), f39);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else if (op_type.equals("hnyjy")) {

                Up_RundataUtils up_rundataUtils = new Up_RundataUtils();
                try {
                    up_rundataUtils.packRequest("0200", "440200",
                            beans.get(positions).getBalanceofAccount(), "1", run_time, String.valueOf(num), f39);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else if (op_type.equals("ltcx")) {


                Up_RundataUtils up_rundataUtils = new Up_RundataUtils();
                try {
                    up_rundataUtils.packRequest("0200", "532200",
                            inputRechargeAmountEdtext.getText().toString().trim(), "1", run_time, String.valueOf(num), f39);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } else if (op_type.equals("ltcx")) {
                Up_RundataUtils up_rundataUtils = new Up_RundataUtils();
                try {
                    up_rundataUtils.packRequest("0200", "532100",
                            inputRechargeAmountEdtext.getText().toString().trim(), "1", run_time, String.valueOf(num), f39);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            Logger.e("����ʧ��:[{}]-[{}]" + respcode + rsp.getStringValue(40));
            final IsoMessage finalRsp = rsp;
            ChargeAgencyActivity.this.runOnUiThread(new Runnable() {
                @SuppressLint("WrongConstant")
                @Override
                public void run() {
                    Toast.makeText(getApplicationContext(), finalRsp.getStringValue(40), 5000).show();
                }
            });

            this.finish();
        }
    }

    private void unpackReSpone(IsoMessage response, String op_type) {
        f39 = response.getStringValue(39);
        rwNUm = response.getStringValue(37);
        String f123 = response.getStringValue(123);
        if (response.getField(123) != null) {

            if (op_type.equals("ydcx")) {
                SpUtils.getSPUtil(getApplicationContext()).putString("all_make_type", "ydcx");
                final String name = f123.substring(0, 5).replace(" ", "");
                //客户名称 GBK30
                yd_namas = f123.split("S");
                ht_num = f123.substring(f123.length() - 50, f123.length() - 30);
                Logger.e(ht_num + "ht_num");
                String type = f123.substring(f123.length() - 53, f123.length() - 50);
                String types = null;
                if (type.equals("S10")) {
                    types = "缴话费";
                } else if (type.equals("S20")) {
                    types = "预存话费";
                } else if (type.equals("S30")) {
                    types = "充值";
                }
                Logger.e(type + "type");
                final String mon = f123.substring(f123.length() - 30, f123.length() - 15).replace(" ", "");
                Logger.e(mon);

                final String finalTypes = types;
                runnable = new Runnable() {
                    @Override
                    public void run() {
                        dealingLayout.setVisibility(View.GONE);
                        inputRechargeAmountPhoneNum.setText(inputPhoneEdtext.getText().toString());
                        inputRechargeAmountName.setText("*" + name.substring(1));
                        inputRechargeAmountType.setText(finalTypes);
                        inputRechargeAmountBalance.setText("￥" + mon);
                        inputRechargeAmountLayout.setVisibility(View.VISIBLE);
                    }
                };
                handler.postDelayed(runnable, 300);
            } else if (op_type.equals("ydjf")) {

                Up_RundataUtils up_rundataUtils = new Up_RundataUtils();
                try {
                    up_rundataUtils.packRequest("0200", "532100",
                            inputRechargeAmountEdtext.getText().toString().trim(), "0", run_time, String.valueOf(num), f39);
                } catch (IOException e) {
                    e.printStackTrace();
                }


                SpUtils.getSPUtil(getApplicationContext()).putString("all_make_type", "ydjf");
                PzGetUtils pzGetUtils = new PzGetUtils();
                pz_nums = pzGetUtils.pzutil(getApplication());


                final String time = f123.substring(20, 28);
                final String info = f123.substring(39, 67).replace(" ", "");
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        dealingLayout.setVisibility(View.GONE);
                        topupSuccessNum.setText(inputPhoneEdtext.getText().toString().trim());
                        topupSuccessTime.setText(time);
                        topupSuccessType.setText("缴话费");
                        topupSuccessTypesey.setText(info);
                        topupSuccessLayout.setVisibility(View.VISIBLE);
                    }
                });
//正常交易
                Gson gson = new Gson();
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");// HH:mm:ss
                //获取当前时间
                Date date = new Date(System.currentTimeMillis());
                Logger.e("Date获取当前日期时间" + simpleDateFormat.format(date).replace("/", ""));
                StatisticalData_bean bean;
                if (jf_type.equals("1")) {
                    bean = new StatisticalData_bean(rwNUm, inputRechargeAmountEdtext.getText().toString().trim(), time, "移动缴费", Constants.DEMO_F102, yd_namas[0], SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""), String.valueOf(pz_nums));

                } else {
                    bean = new StatisticalData_bean(rwNUm, inputRechargeAmountEdtext.getText().toString().trim(), time, "移动缴费", bindNum, yd_namas[0], SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""), String.valueOf(pz_nums));

                }
                String STAT_DATA = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", ""), "");

                List<StatisticalData_bean> beans = gson.fromJson(STAT_DATA, new TypeToken<List<StatisticalData_bean>>() {
                }.getType());
                beans.add(bean);

                SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", ""), gson.toJson(beans));


//汇总查询
                String STAT_DATAALL = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", "");
                List<Summary_Bean> beanalls = gson.fromJson(STAT_DATAALL, new TypeToken<List<Summary_Bean>>() {
                }.getType());
                if (!beanalls.get(0).getYdhf().equals("")) {
                    double money;
                    String data[] = beanalls.get(0).getYdhf().split(",");

                    if (data[0].contains(".") && inputRechargeAmountEdtext.getText().toString().contains(".")) {
                        money = Double.parseDouble(data[0]) + Double.parseDouble(inputRechargeAmountEdtext.getText().toString());
                    } else if (data[0].contains(".") && !inputRechargeAmountEdtext.getText().toString().contains(".")) {
                        money = Double.parseDouble(data[0]) + Integer.parseInt(inputRechargeAmountEdtext.getText().toString());
                    } else if (!data[0].contains(".") && inputRechargeAmountEdtext.getText().toString().contains(".")) {
                        money = Integer.valueOf(data[0]) + Double.parseDouble(inputRechargeAmountEdtext.getText().toString());
                    } else {
                        money = Integer.valueOf(data[0]) + Integer.valueOf(inputRechargeAmountEdtext.getText().toString());
                    }
//                BigDecimal n = new BigDecimal("0");

                    Logger.e(Double.parseDouble(data[0]) + "bbbbbbbbbbbbbb");
                    int num = Integer.valueOf(data[1]) + 1;
                    String ydjf = money + "," + num;
                    Summary_Bean summary_bean = new Summary_Bean(beanalls.get(0).getZnqk(), beanalls.get(0).getXjhk(), beanalls.get(0).getZzhk(), ydjf, beanalls.get(0).getLthf(), beanalls.get(0).getSgcc(), beanalls.get(0).getDzh(), beanalls.get(0).getHzd(), beanalls.get(0).getZhgm(), beanalls.get(0).getLwhc(), beanalls.get(0).getKtgs(), "", "", beanalls.get(0).getZhcqy(), beanalls.get(0).getZhcjy(), beanalls.get(0).getHnyqy(), beanalls.get(0).getHnyjy());
                    beanalls.clear();
                    beanalls.add(summary_bean);
                    Logger.e(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA");
                    SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", gson.toJson(beanalls));

                } else {
                    int num = 1;
                    String money = inputRechargeAmountEdtext.getText().toString();
                    String ydhf = money + "," + num;
                    Summary_Bean summary_bean = new Summary_Bean(beanalls.get(0).getZnqk(), beanalls.get(0).getXjhk(), beanalls.get(0).getZzhk(), ydhf, beanalls.get(0).getLthf(), beanalls.get(0).getSgcc(), beanalls.get(0).getDzh(), beanalls.get(0).getHzd(), beanalls.get(0).getZhgm(), beanalls.get(0).getLwhc(), beanalls.get(0).getKtgs(), "", "", beanalls.get(0).getZhcqy(), beanalls.get(0).getZhcjy(), beanalls.get(0).getHnyqy(), beanalls.get(0).getHnyjy());
                    beanalls.clear();
                    beanalls.add(summary_bean);
                    Logger.e(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA");
                    SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", gson.toJson(beanalls));

                }


            } else if (op_type.equals("ltcx")) {
                SpUtils.getSPUtil(getApplicationContext()).putString("all_make_type", "ltcx");
                String lt_namas = f123.replaceAll("[^\\u4e00-\\u9fa5]", "");
                if (lt_namas.length() == 2) {
                    lt_name = lt_namas + "                          ";
                } else if (lt_namas.length() == 3) {
                    lt_name = lt_namas + "                        ";
                } else if (lt_namas.length() == 4) {
                    lt_name = lt_namas + "                      ";
                } else if (lt_namas.length() == 5) {
                    lt_name = lt_namas + "                    ";
                }
                final String name = lt_namas.substring(1);
                ht_num = f123.substring(0, 19);
                Logger.e(name + "" + ht_num);
                final String mon = f123.substring(65 - lt_namas.length(), 79 - lt_namas.length()).replaceAll(" ", "");
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        dealingLayout.setVisibility(View.GONE);
                        inputRechargeAmountPhoneNum.setText(inputPhoneEdtext.getText().toString());
                        inputRechargeAmountName.setText("*" + name);
                        inputRechargeAmountType.setText("充值");
                        inputRechargeAmountBalance.setText("￥" + mon);
                        inputRechargeAmountLayout.setVisibility(View.VISIBLE);
                    }
                });


            } else if (op_type.equals("ltjf")) {
                Up_RundataUtils up_rundataUtils = new Up_RundataUtils();
                try {
                    up_rundataUtils.packRequest("0200", "532200",
                            inputRechargeAmountEdtext.getText().toString().trim(), "0", run_time, String.valueOf(num), f39);
                } catch (IOException e) {
                    e.printStackTrace();
                }

                SpUtils.getSPUtil(getApplicationContext()).putString("all_make_type", "ltjf");
                PzGetUtils pzGetUtils = new PzGetUtils();
                pz_nums = pzGetUtils.pzutil(getApplication());


                final String time = f123.substring(20, 28);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        dealingLayout.setVisibility(View.GONE);
                        topupSuccessNum.setText(inputPhoneEdtext.getText().toString().trim());
                        topupSuccessTime.setText(time);
                        topupSuccessType.setText("缴话费");
                        topupSuccessTypesey.setText("缴话费");
                        topupSuccessLayout.setVisibility(View.VISIBLE);
                    }
                });
//正常交易
                Gson gson = new Gson();
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");// HH:mm:ss
                //获取当前时间
                Date date = new Date(System.currentTimeMillis());
                Logger.e("Date获取当前日期时间" + simpleDateFormat.format(date).replace("/", ""));
                StatisticalData_bean bean;
                if (jf_type.equals("1")) {
                    bean = new StatisticalData_bean(rwNUm, inputRechargeAmountEdtext.getText().toString().trim(), time, "联通缴费", Constants.DEMO_F102, lt_name, SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""), String.valueOf(pz_nums));

                } else {
                    bean = new StatisticalData_bean(rwNUm, inputRechargeAmountEdtext.getText().toString().trim(), time, "联通缴费", bindNum, lt_name, SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""), String.valueOf(pz_nums));
                }
                String STAT_DATA = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", ""), "");

                List<StatisticalData_bean> beans = gson.fromJson(STAT_DATA, new TypeToken<List<StatisticalData_bean>>() {
                }.getType());
                beans.add(bean);

                SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", ""), gson.toJson(beans));


                //汇总查询
                String STAT_DATAALL = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", "");
                List<Summary_Bean> beanalls = gson.fromJson(STAT_DATAALL, new TypeToken<List<Summary_Bean>>() {
                }.getType());
                if (!beanalls.get(0).getLthf().equals("")) {
                    double money;
                    String data[] = beanalls.get(0).getLthf().split(",");

                    if (data[0].contains(".") && inputRechargeAmountEdtext.getText().toString().contains(".")) {
                        money = Double.parseDouble(data[0]) + Double.parseDouble(inputRechargeAmountEdtext.getText().toString());
                    } else if (data[0].contains(".") && !inputRechargeAmountEdtext.getText().toString().contains(".")) {
                        money = Double.parseDouble(data[0]) + Integer.parseInt(inputRechargeAmountEdtext.getText().toString());
                    } else if (!data[0].contains(".") && inputRechargeAmountEdtext.getText().toString().contains(".")) {
                        money = Integer.valueOf(data[0]) + Double.parseDouble(inputRechargeAmountEdtext.getText().toString());
                    } else {
                        money = Integer.valueOf(data[0]) + Integer.valueOf(inputRechargeAmountEdtext.getText().toString());
                    }
//                BigDecimal n = new BigDecimal("0");

                    Logger.e(Double.parseDouble(data[0]) + "bbbbbbbbbbbbbb");
                    int num = Integer.valueOf(data[1]) + 1;
                    String ltjf = money + "," + num;
                    Summary_Bean summary_bean = new Summary_Bean(beanalls.get(0).getZnqk(), beanalls.get(0).getXjhk(), beanalls.get(0).getZzhk(), beanalls.get(0).getYdhf(), ltjf, beanalls.get(0).getSgcc(), beanalls.get(0).getDzh(), beanalls.get(0).getHzd(), beanalls.get(0).getZhgm(), beanalls.get(0).getLwhc(), beanalls.get(0).getKtgs(), "", "", beanalls.get(0).getZhcqy(), beanalls.get(0).getZhcjy(), beanalls.get(0).getHnyqy(), beanalls.get(0).getHnyjy());
                    beanalls.clear();
                    beanalls.add(summary_bean);
                    Logger.e(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA");
                    SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", gson.toJson(beanalls));

                } else {
                    int num = 1;
                    String money = inputRechargeAmountEdtext.getText().toString();
                    String ltjf = money + "," + num;
                    Summary_Bean summary_bean = new Summary_Bean(beanalls.get(0).getZnqk(), beanalls.get(0).getXjhk(), beanalls.get(0).getZzhk(), beanalls.get(0).getYdhf(), ltjf, beanalls.get(0).getSgcc(), beanalls.get(0).getDzh(), beanalls.get(0).getHzd(), beanalls.get(0).getZhgm(), beanalls.get(0).getLwhc(), beanalls.get(0).getKtgs(), "", "", beanalls.get(0).getZhcqy(), beanalls.get(0).getZhcjy(), beanalls.get(0).getHnyqy(), beanalls.get(0).getHnyjy());
                    beanalls.clear();
                    beanalls.add(summary_bean);
                    Logger.e(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA");
                    SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", gson.toJson(beanalls));

                }


            } else if (op_type.equals("zhrz")) {
                SpUtils.getSPUtil(getApplicationContext()).putString("all_make_type", "zhrz");
                String f123s[] = f123.split("\\|");

                username = f123s[2];
                jgh = f123s[0];
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (make_type.equals("hnyqy")) {
                            ficationingLayout.setVisibility(View.GONE);
                            inputCustomanagerLayout.setVisibility(View.VISIBLE);
                        } else if (make_type.equals("hnyjy")) {
                            new Thread(new Runnable() {
                                @Override
                                public void run() {
                                    num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0);
                                    Logger.e("第一次获取rz" + num);
                                    excuteSBA(String.valueOf(num));
                                    SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", num + 1);
                                    Logger.e("第二次获取rz" + SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0));
                                }
                            }).start();

                        }
                    }
                });
            } else if (op_type.equals("zhcx")) {
                SpUtils.getSPUtil(getApplicationContext()).putString("all_make_type", "zhcx");
                //子账户查询
                if (response.getStringValue(59) == null) {
                    f59_dq = false;
                } else {
                    if (response.getStringValue(59).substring(0, 1).equals("0")) {
                        f59_dq = true;
                        f59data = "2" + response.getStringValue(59).substring(1, response.getStringValue(59).length());
                    } else {
                        f59_dq = false;
                    }
                }
                beans = new ArrayList<>();
                List<Map<String, String>> list = new ArrayList<Map<String, String>>();
                // 子账户信息
                if (response.getField(123) != null) {


//			System.out.println("f123=["+f123+"]");
                    f123 = f123 + " ";// 防止末尾没有内容导致 split 函数计算不准确
                    String notes[] = f123.split("[\u007c]");

                    String custname = notes[0]; // 客户名称
                    String signflag = notes[1]; // 签约标志
                    String prodname = notes[2]; // 理财产品名称
                    String snum = notes[3]; // 明细笔数
                    int num = Integer.parseInt(snum);
                    name = custname;
                    System.out.println("客户名称=[" + custname + "]");
                    System.out.println("签约标志=[" + signflag + "]");
                    System.out.println("理财产品名称=[" + prodname + "]");
//			System.out.println("snum=["+snum+"]");

                    unpackF123(4, num, notes, list);

                }
                // 当客户子账户过多时，第123域存放不完时，剩余的部分放在120域下发
                if (response.getField(120) != null) {
                    String f120 = response.getStringValue(120);

//			System.out.println("f120=["+f120+"]");
                    f120 = f120 + " ";// 防止末尾没有内容导致 split 函数计算不准确
                    String notes[] = f120.split("[\u007c]");
                    String snum = notes[0]; // 明细笔数
                    int num = Integer.parseInt(snum);
                    unpackF123(1, num, notes, list);

                }

//		System.out.println("list="+list);
                for (int i = 0; i < list.size(); i++) {
                    Map<String, String> data = list.get(i);
                    System.out.println("第" + i + "个子账户信息=" + data);
                }
            } else if (op_type.equals("hnyqy")) {
                Up_RundataUtils up_rundataUtils = new Up_RundataUtils();
                try {
                    up_rundataUtils.packRequest("0200", "440100",
                            inputMoneyEdtext.getText().toString().trim(), "0", run_time, String.valueOf(num), f39);
                } catch (IOException e) {
                    e.printStackTrace();
                }


                SpUtils.getSPUtil(getApplicationContext()).putString("all_make_type", "hnyqy");
                PzGetUtils pzGetUtils = new PzGetUtils();
                pz_nums = pzGetUtils.pzutil(getApplication());

                //活转定
                int f123_l = response.getStringValue(123).length();
                String lv = response.getStringValue(123).substring(55, 63);
                Logger.e(lv + "lv");
                String lvs = "";

                if (lv.equals("00000000")) {
                    lvs = "0%";
                } else {
                    String lv_first = lv.replaceFirst("^0+", "").substring(0, 1);
                    int l = lv.replaceFirst("^0+", "").length() - 1;
                    String lv_ed = lv.replaceFirst("^0+", "").substring(lv.replaceFirst("^0+", "").length() - l);
                    lvs = lv_first + "." + lv_ed + "%";
                }
                final String finalLvs = lvs;
                //戶名
                String names = response.getStringValue(123).substring(71, 131);
                String reg = "[^\u4e00-\u9fa5]";

                name = names.replaceAll(reg, " ").substring(0, 5);
                dqzh = response.getStringValue(123).substring(4, 10);

//余额
                String ye = response.getStringValue(123).substring(f123_l - 44, f123_l - 29);
//            //起息日
//            qxr = response.getStringValue(123).substring(64, 71);
//            Logger.e(qxr.length() + "" + qxr);
                //到昔日
                dxr = response.getStringValue(123).substring(63, 71);
                Logger.e("{" + dxr + "}");
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        dealingLayout.setVisibility(View.GONE);
                        chargeAgencyHomeLayout.setVisibility(View.GONE);
                        liveTransfersSuccessLayout.setVisibility(View.VISIBLE);
                        liveTransfersZcRlayout.setVisibility(View.GONE);
                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");// HH:mm:ss
                        //获取当前时间
                        Date date = new Date(System.currentTimeMillis());

                        liveTransfersSuccessMoney.setText("￥" + inputMoneyEdtext.getText().toString());
                        liveTransfersSuccessUsernum.setText(bindNum);
                        liveTransfersSuccessDealtype.setText("惠农赢1号");
                        liveTransfersSuccessTime.setText("369天");
                        liveTransfersSuccessLayout.setVisibility(View.VISIBLE);
                        liveTransfersSuccessRateofinterest.setText(finalLvs);
                        liveTransfersSuccessUpdata.setText(simpleDateFormat.format(date).replaceAll("/", ""));

                    }
                });

                //正常交易
                Gson gson = new Gson();
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");// HH:mm:ss
                //获取当前时间
                Date date = new Date(System.currentTimeMillis());
                Logger.e("Date获取当前日期时间" + simpleDateFormat.format(date).replace("/", ""));
                StatisticalData_bean bean = new StatisticalData_bean(rwNUm, inputMoneyEdtext.getText().toString().trim(), time, "惠农赢签约", bindNum, username, SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""), String.valueOf(pz_nums));
                String STAT_DATA = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", ""), "");

                List<StatisticalData_bean> beans = gson.fromJson(STAT_DATA, new TypeToken<List<StatisticalData_bean>>() {
                }.getType());
                beans.add(bean);

                SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", ""), gson.toJson(beans));


                //汇总查询
                String STAT_DATAALL = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", "");
                List<Summary_Bean> beanalls = gson.fromJson(STAT_DATAALL, new TypeToken<List<Summary_Bean>>() {
                }.getType());
                if (!beanalls.get(0).getHnyqy().equals("")) {
                    double money;
                    String data[] = beanalls.get(0).getHnyqy().split(",");

                    if (data[0].contains(".") && inputMoneyEdtext.getText().toString().contains(".")) {
                        money = Double.parseDouble(data[0]) + Double.parseDouble(inputMoneyEdtext.getText().toString());
                    } else if (data[0].contains(".") && !inputMoneyEdtext.getText().toString().contains(".")) {
                        money = Double.parseDouble(data[0]) + Integer.parseInt(inputMoneyEdtext.getText().toString());
                    } else if (!data[0].contains(".") && inputMoneyEdtext.getText().toString().contains(".")) {
                        money = Integer.valueOf(data[0]) + Double.parseDouble(inputMoneyEdtext.getText().toString());
                    } else {
                        money = Integer.valueOf(data[0]) + Integer.valueOf(inputMoneyEdtext.getText().toString());
                    }
//                BigDecimal n = new BigDecimal("0");

                    Logger.e(Double.parseDouble(data[0]) + "bbbbbbbbbbbbbb");
                    int num = Integer.valueOf(data[1]) + 1;
                    String hnyqy = money + "," + num;
                    Summary_Bean summary_bean = new Summary_Bean(beanalls.get(0).getZnqk(), beanalls.get(0).getXjhk(), beanalls.get(0).getZzhk(), beanalls.get(0).getYdhf(), beanalls.get(0).getLthf(), beanalls.get(0).getSgcc(), beanalls.get(0).getDzh(), beanalls.get(0).getHzd(), beanalls.get(0).getZhgm(), beanalls.get(0).getLwhc(), beanalls.get(0).getKtgs(), "", "", beanalls.get(0).getZhcqy(), beanalls.get(0).getZhcjy(), hnyqy, beanalls.get(0).getHnyjy());
                    beanalls.clear();
                    beanalls.add(summary_bean);
                    Logger.e(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA");
                    SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", gson.toJson(beanalls));

                } else {
                    int num = 1;
                    String money = inputMoneyEdtext.getText().toString();
                    String hnyqy = money + "," + num;
                    Summary_Bean summary_bean = new Summary_Bean(beanalls.get(0).getZnqk(), beanalls.get(0).getXjhk(), beanalls.get(0).getZzhk(), beanalls.get(0).getYdhf(), beanalls.get(0).getLthf(), beanalls.get(0).getSgcc(), beanalls.get(0).getDzh(), beanalls.get(0).getHzd(), beanalls.get(0).getZhgm(), beanalls.get(0).getLwhc(), beanalls.get(0).getKtgs(), "", "", beanalls.get(0).getZhcqy(), beanalls.get(0).getZhcjy(), hnyqy, beanalls.get(0).getHnyjy());
                    beanalls.clear();
                    beanalls.add(summary_bean);
                    Logger.e(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA");
                    SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", gson.toJson(beanalls));

                }


            } else if (op_type.equals("hnyjy")) {

                Up_RundataUtils up_rundataUtils = new Up_RundataUtils();
                try {
                    up_rundataUtils.packRequest("0200", "440200",
                            beans.get(positions).getBalanceofAccount(), "0", run_time, String.valueOf(num), f39);
                } catch (IOException e) {
                    e.printStackTrace();
                }


                SpUtils.getSPUtil(getApplicationContext()).putString("all_make_type", "hnyjy");
                PzGetUtils pzGetUtils = new PzGetUtils();
                pz_nums = pzGetUtils.pzutil(getApplication());

                String lxb = "";
                String lxa = "";
                cq = f123.substring(f123.length() - 21, f123.length() - 16).replaceFirst("^0+", "");
                Logger.e(f123.substring(25, 40));
                if (f123.substring(25, 40).equals("000000000000000")) {
                    lx = "0";
                } else {
                    lxa = f123.substring(25, 40).replaceFirst("^0+", "").substring(0, f123.substring(25, 40).replaceFirst("^0+", "").length() - 2);
                    if (f123.substring(25, 40).replaceFirst("^0+", "").length() == 1) {
                        lxb = "0" + f123.substring(25, 40).replaceFirst("^0+", "").substring(f123.substring(25, 40).replaceFirst("^0+", "").length() - 1);
                    } else {
                        lxb = f123.substring(25, 40).replaceFirst("^0+", "").substring(f123.substring(25, 40).replaceFirst("^0+", "").length() - 2);
                    }

                    if (lxa == "") {
                        lx = "0" + "." + lxb;
                    } else {
                        lx = lxa + "." + lxb;
                    }
                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        chargeAgencyHomeLayout.setVisibility(View.GONE);
                        switchSuccessUsernum.setText(bindNum);
                        switchSuccessMoney.setText(beans.get(positions).getBalanceofAccount());
                        switchSuccessTime.setText(beans.get(positions).getPrdsdep());
                        switchSuccessUpday.setText(beans.get(positions).getValuedate());
                        switchSuccessStopday.setText(beans.get(positions).getDuedate());
                        switchSuccessInterest.setText(lx);
                        switchSuccessDealtype.setText("惠农赢解约");
                        switchSuccessLayout.setVisibility(View.VISIBLE);
                    }
                });

                //正常交易
                Gson gson = new Gson();
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");// HH:mm:ss
                //获取当前时间
                Date date = new Date(System.currentTimeMillis());
                Logger.e("Date获取当前日期时间" + simpleDateFormat.format(date).replace("/", ""));
                StatisticalData_bean bean = new StatisticalData_bean(rwNUm, beans.get(positions).getBalanceofAccount(), time, "惠农赢解约", bindNum, username, SpUtils.getSPUtil(getApplicationContext()).getString("make_user", ""), String.valueOf(pz_nums));
                String STAT_DATA = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", ""), "");

                List<StatisticalData_bean> beanss = gson.fromJson(STAT_DATA, new TypeToken<List<StatisticalData_bean>>() {
                }.getType());
                beanss.add(bean);

                SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", ""), gson.toJson(beanss));


                //汇总查询
                String STAT_DATAALL = SpUtils.getSPUtil(getApplicationContext()).getString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", "");
                List<Summary_Bean> beanalls = gson.fromJson(STAT_DATAALL, new TypeToken<List<Summary_Bean>>() {
                }.getType());
                if (!beanalls.get(0).getHnyjy().equals("")) {
                    double money;
                    String data[] = beanalls.get(0).getHnyjy().split(",");

                    if (data[0].contains(".")) {
                        money = Double.parseDouble(data[0]) + Integer.valueOf(beans.get(positions).getBalanceofAccount());

                    } else {
                        money = Integer.valueOf(data[0]) + Integer.valueOf(beans.get(positions).getBalanceofAccount());
                    }
//                BigDecimal n = new BigDecimal("0");

                    Logger.e(Double.parseDouble(data[0]) + "bbbbbbbbbbbbbb");
                    int num = Integer.valueOf(data[1]) + 1;
                    String getHnyjy = money + "," + num;
                    Summary_Bean summary_bean = new Summary_Bean(beanalls.get(0).getZnqk(), beanalls.get(0).getXjhk(), beanalls.get(0).getZzhk(), beanalls.get(0).getYdhf(), beanalls.get(0).getLthf(), beanalls.get(0).getSgcc(), beanalls.get(0).getDzh(), beanalls.get(0).getHzd(), beanalls.get(0).getZhgm(), beanalls.get(0).getLwhc(), beanalls.get(0).getKtgs(), "", "", beanalls.get(0).getZhcqy(), beanalls.get(0).getZhcjy(), beanalls.get(0).getHnyqy(), getHnyjy);
                    beanalls.clear();
                    beanalls.add(summary_bean);
                    Logger.e(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA");
                    SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", gson.toJson(beanalls));

                } else {
                    int num = 1;
                    String money = beans.get(positions).getBalanceofAccount();
                    String getHnyjy = money + "," + num;
                    Summary_Bean summary_bean = new Summary_Bean(beanalls.get(0).getZnqk(), beanalls.get(0).getXjhk(), beanalls.get(0).getZzhk(), beanalls.get(0).getYdhf(), beanalls.get(0).getLthf(), beanalls.get(0).getSgcc(), beanalls.get(0).getDzh(), beanalls.get(0).getHzd(), beanalls.get(0).getZhgm(), beanalls.get(0).getLwhc(), beanalls.get(0).getKtgs(), "", "", beanalls.get(0).getZhcqy(), beanalls.get(0).getZhcjy(), beanalls.get(0).getHnyqy(), getHnyjy);
                    beanalls.clear();
                    beanalls.add(summary_bean);
                    Logger.e(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA");
                    SpUtils.getSPUtil(getApplicationContext()).putString(simpleDateFormat.format(date).replace("/", "") + "ALL_DATA", gson.toJson(beanalls));

                }


            }
        }
    }

    /**
     * @param start 从第几个子域开始为记录内容
     * @param num   记录条数
     * @param notes 拆包子域集合
     * @param list  返回的拆包结果
     */
    private void unpackF123(int start, int num, String notes[], List<Map<String, String>> list) {

        // 每一条明细记录有17个子域
        int nrecod = 17;

        if (f59num != 0) {
            for (int i = 0; i < num; i++) {

                Map<String, String> data = new HashMap<String, String>();
                String prdcode = notes[start + i * nrecod + 0]; // 产品代码

                // 产品名称
                String pdpname = notes[start + i * nrecod + 1];

                String pdpcode = notes[start + i * nrecod + 2]; // 账户编号
                f122_3 = pdpcode;

                // 理财帐户笔号
                String seqno = notes[start + i * nrecod + 3];
                f122_4 = seqno;

                String acctsts = notes[start + i * nrecod + 4]; // 帐户状态

                // 帐户余额
                String opacamt = notes[start + i * nrecod + 5];

                String acctbal = notes[start + i * nrecod + 6]; // 可用余额

                // 起息日期
                String valdt = notes[start + i * nrecod + 7];

                // 存期
                String depprd = notes[start + i * nrecod + 8];

                // 到期日期
                String duedt = notes[start + i * nrecod + 9];

                String mngflg = notes[start + i * nrecod + 10]; // 自动转存标志

                String prdsdep = notes[start + i * nrecod + 11]; // 约定存期

                // 利率
                String trndintc = notes[start + i * nrecod + 12];

                String drwdt = notes[start + i * nrecod + 13]; // 通知支取日期

                String drwdsgn = notes[start + i * nrecod + 14]; // 通知支取设定

                String drwamt = notes[start + i * nrecod + 15]; // 通知支取金额

                String curiden = notes[start + i * nrecod + 16]; // 钞汇鉴别
                curiden = curiden.trim();

                String lv_first = trndintc.substring(2, 3);
                String lv_ed = trndintc.substring(3, trndintc.length());
                String lv = lv_first + "." + lv_ed + "%";
                int monl = opacamt.replaceFirst("^0+", "").length();
                String money = opacamt.replaceFirst("^0+", "").substring(0, monl - 2);

                Select_subaccount_Bean bean = new
                        Select_subaccount_Bean(pdpname, pdpcode, seqno, money, valdt, duedt, lv, pdpname.substring(0, 3), lv);
                beans.add(bean);
                for (int n = 0; n < beans.size(); n++) {
                    if (!beans.get(n).getName().equals("惠农赢1号")) {
                        beans.remove(n);
                    }
                }
            }
//            runOnUiThread(new Runnable() {
//                @Override
//                public void run() {
//                    adapter.addData(beans);
//                }
//            });
        } else {
            for (int i = 0; i < num; i++) {

                Map<String, String> data = new HashMap<String, String>();
                String prdcode = notes[start + i * nrecod + 0]; // 产品代码

                // 产品名称
                String pdpname = notes[start + i * nrecod + 1];

                String pdpcode = notes[start + i * nrecod + 2]; // 账户编号
                f122_3 = pdpcode;

                // 理财帐户笔号
                String seqno = notes[start + i * nrecod + 3];
                f122_4 = seqno;

                String acctsts = notes[start + i * nrecod + 4]; // 帐户状态

                // 帐户余额
                String opacamt = notes[start + i * nrecod + 5];

                String acctbal = notes[start + i * nrecod + 6]; // 可用余额

                // 起息日期
                String valdt = notes[start + i * nrecod + 7];

                // 存期
                String depprd = notes[start + i * nrecod + 8];

                // 到期日期
                String duedt = notes[start + i * nrecod + 9];

                String mngflg = notes[start + i * nrecod + 10]; // 自动转存标志

                String prdsdep = notes[start + i * nrecod + 11]; // 约定存期

                // 利率
                String trndintc = notes[start + i * nrecod + 12];

                String drwdt = notes[start + i * nrecod + 13]; // 通知支取日期

                String drwdsgn = notes[start + i * nrecod + 14]; // 通知支取设定

                String drwamt = notes[start + i * nrecod + 15]; // 通知支取金额

                String curiden = notes[start + i * nrecod + 16]; // 钞汇鉴别
                curiden = curiden.trim();

                String lv_first = trndintc.substring(2, 3);
                String lv_ed = trndintc.substring(3, trndintc.length());
                String lv = lv_first + "." + lv_ed + "%";
                int monl = opacamt.replaceFirst("^0+", "").length();
                String money = opacamt.replaceFirst("^0+", "").substring(0, monl - 2);

                Select_subaccount_Bean bean = new
                        Select_subaccount_Bean(pdpname, pdpcode, seqno, money, valdt, duedt, lv, pdpname.substring(0, 3), lv);
                beans.add(bean);
                for (int n = 0; n < beans.size(); n++) {
                    if (!beans.get(n).getName().equals("惠农赢1号")) {
                        beans.remove(n);
                    }
                }
            }
        }
        if (f59_dq) {


            Logger.e("qqqqqqqqq");
            sb_num = sb_num + 1;
            f59num = f59num + 1;

            Logger.e("nums1111111111" + sb_num);


            excuteSBA(String.valueOf(sb_num));
//                    SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", nums + 1);
//                    Logger.e("nums2" + SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0));


        } else {
            f59num = f59num + 2;
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Logger.e(beans.size() + "");
//                    if (f59num == 0) {
                    initdqrecycler(beans);
                    ficationingLayout.setVisibility(View.GONE);
                    chargeAgencyHomeLayout.setVisibility(View.GONE);
                    selectSubaccountLayout.setVisibility(View.VISIBLE);

//                    }
                }
            });
        }


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Logger.e("ondistory");

        if (make_type == "hnyjy") {

            int num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0);
            SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", sb_num + f59num);
        }

    }

    private void initdqrecycler(final List<Select_subaccount_Bean> select_beans) {

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
        selectSubaccountRecyclerview.setLayoutManager(linearLayoutManager);
        adapter = new Select_subaccount_adapter(R.layout.select_subaccount_adapter_item_layout, select_beans, "");
        selectSubaccountRecyclerview.setAdapter(adapter);
        adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, final int position) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        dqzh = beans.get(position).getNum();
                        qxr1 = beans.get(position).getValuedate();
                        dxr1 = beans.get(position).getDuedate();
                        positions = position;
                        pleaseInputIccardLayout.setVisibility(View.GONE);
                        dealingLayout.setVisibility(View.GONE);
                        selectSubaccountLayout.setVisibility(View.GONE);
                        chargeAgencyHomeLayout.setVisibility(View.VISIBLE);
//                        homeCardLayout.setVisibility(View.VISIBLE);
                        connectedToLayout.setVisibility(View.VISIBLE);
                    }
                });

            }
        });

//
//        adapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
//            @Override
//            public void onLoadMoreRequested() {
//                selectSubaccountRecyclerview.postDelayed(new Runnable() {
//                    @Override
//                    public void run() {
//                        /**
//                         *  Alltotal是总条数，每次上拉加载10条数据
//                         *  每次上拉total可以+10
//                         *  Alltotal>total
//                         *  可以继续上拉加载
//                         *  <=表示数据已经加载完毕
//                         */
//
//                        if (f59_dq) {
//                            adapter.loadMoreComplete();
//                            new Thread(new Runnable() {
//                                @Override
//                                public void run() {
//                                    setOnLoadzzhcxMoreData();
//                                }
//                            }).start();
//
//
//                        } else {
//                            adapter.loadMoreEnd();
//                        }
//                    }
//                }, 3000);
//            }
//        });
    }

    private void setOnLoadzzhcxMoreData() {
        f59num = f59num + 1;
        num = SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 0);
        Logger.e("第一次获取" + num);
        excuteSBA(String.valueOf(num));
        SpUtils.getSPUtil(getApplicationContext()).putInt("s_Num", num + 1);
        Logger.e("第二次获取" + SpUtils.getSPUtil(getApplicationContext()).getInt("s_Num", 1000));
    }


}